{% extends "account/base.html" %}

{% load i18n %}
{% load uni_form_tags %}

{% block head_title %}{% trans "Account" %}{% endblock %}

{% block content %}
    <h1>{% trans "E-mail Addresses" %}</h1>

{% if user.emailaddress_set.all %}
<p>{% trans 'The following e-mail addresses are associated to your account:' %}</p>

<form action="{% url 'account_email' %}" class="email_list uniForm" method="post">
{% csrf_token %}
<fieldset class="blockLabels">

  {% for emailaddress in user.emailaddress_set.all %}
<div class="ctrlHolder">
      <label for="email_radio_{{ forloop.counter }}" class="{% if emailaddress.primary %}primary_email{% endif %}">

      <input id="email_radio_{{ forloop.counter }}" type="radio" name="email" {% if emailaddress.primary %}checked="checked"{% endif %} value="{{ emailaddress.email }}"/>

{{ emailaddress.email }}
    {% if emailaddress.verified %}
    <span class="verified">{% trans "Verified" %}</span>
    {% else %}
    <span class="unverified">{% trans "Unverified" %}</span>
    {% endif %}
      {% if emailaddress.primary %}<span class="primary">{% trans "Primary" %}</span>{% endif %}
</label>
</div>
  {% endfor %}

<div class="buttonHolder">
      <button class="secondaryAction" type="submit" name="action_primary" >{% trans 'Make Primary' %}</button>
      <button class="secondaryAction" type="submit" name="action_send" >{% trans 'Re-send Verification' %}</button>
      <button class="primaryAction" type="submit" name="action_remove" >{% trans 'Remove' %}</button>
</div>

</fieldset>
</form>

{% else %}
<p><strong>{% trans 'Warning:'%}</strong> {% trans "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}</p>

{% endif %}


    <h2>{% trans "Add E-mail Address" %}</h2>

    <form method="post" action="" class="add_email uniForm">
        {% csrf_token %}
        <fieldset class="inlineLabels">
            {{ add_email_form|as_uni_form }}
             <div class = "buttonHolder">
                 <button name="action_add" type="submit">{% trans "Add E-mail" %}</button>
            </div>
        </fieldset>
    </form>

{% endblock %}


{% block extra_body %}
<script type="text/javascript">
$(function(){
$("button[name='action_remove']").click(function(){
if (confirm("{% trans 'Do you really want to remove the selected e-mail address?' %}")) {
return true;
}
return false;
});
});
</script>
{% endblock %}
